	 							
package com.module.device.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import base.dao.GenericHibernateDao;
import base.util.Page;
import com.module.device.vo.DeviceType;

public class DeviceTypeDao  extends GenericHibernateDao<DeviceType, Long> {	
	private DeviceTypeDao(){}
	
	private static DeviceTypeDao dao;
	
	public synchronized static DeviceTypeDao getInstance(){
		if(dao==null)
			dao = new DeviceTypeDao();
		return dao;
	}
	/**
	 * 查询列表
	 * @param session
	 * @param bean
	 * @param start
	 * @param limit
	 * @return
	 * @throws SQLException
	 */
	public Page getList(Session session,DeviceType bean,Integer start, Integer limit)throws SQLException{
		Page page = new Page();
		StringBuffer sb = new StringBuffer();
	    StringBuffer condition = new StringBuffer();
		List<Object> params = new ArrayList<Object>();
		sb.append("from DeviceType as obj where 1=1 ");
		Query query = session.createQuery(sb.toString());
		query.setFirstResult(start).setMaxResults(limit);
		Query totalQuery = session
		.createQuery("select count(*) from DeviceType as obj where 1=1 "+condition);
		page.setTotal((long) ((Long) totalQuery.uniqueResult()).intValue());
		page.setRows(query.list());	
		return page;
	}
	
	/**
	 * 查询设备名称列表
	 * @param session
	 * @param bean
	 * @param start
	 * @param limit
	 * @return
	 * @throws SQLException
	 */
	public List findByDeviceTypeName(Session session,String deviceTypeName)throws SQLException{
		StringBuffer sb = new StringBuffer();
		sb.append("from DeviceType as obj where 1=1 and obj.deviceTypeName='"+deviceTypeName+"'");
		Query query = session.createQuery(sb.toString());
		return query.list();
	}
	
	
	
	
	
	
	
}

